package com.cetccloud.ap.proxy.channel.cossDomain.s30.handler.recv;

import com.alibaba.fastjson.JSON;
import com.cetccloud.ap.proxy.channel.cossDomain.s30.S30Adapter;
import com.thunisoft.exchange.gateway.protocol.channel.GatewayChannelMessageType;
import com.thunisoft.exchange.gateway.protocol.channel.GatewayRegisterResponseMessage;
import com.thunisoft.exchange.gateway.protocol.entity.RegisterExchangeNode;
import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @ClassName RegisterRespHandler
 * @Description 自动注册响应
 * @Author superz
 * @Date 2021/5/3 10:47
 * @Version 1.0
 **/
@Slf4j
@Component
public class RegisterRespHandler implements RecvChannelHandler<GatewayRegisterResponseMessage> {

    @Autowired
    private Vertx vertx;

    @Override
    public GatewayChannelMessageType type() {
        return GatewayChannelMessageType.registerResp;
    }

    @Override
    public void handle(GatewayRegisterResponseMessage metadataMessage) {
        log.info("自动注册响应... 数据: {}", JSON.toJSONString(metadataMessage));
        RegisterExchangeNode selfNode = metadataMessage.getMeta();
        vertx.eventBus().publish(S30Adapter.REGISTER_EVENT, JSON.toJSONString(selfNode));
    }
}
